package com.example.tenant.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.tenant.entity.User;
import com.example.tenant.mapper.UserMapper;
import com.example.tenant.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Welisit
 * @since 2020-06-24
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    @Transactional
    public boolean updateUserName(String userId, String username) {
        boolean result = update(new UpdateWrapper<User>().lambda().eq(User::getId, userId).set(User::getUsername, username));
        // 此处报错，检验数据库数据是否修改，事务是否生效
        int i = 10/0;
        update(new UpdateWrapper<User>().lambda().eq(User::getId, userId).set(User::getUsername, "222"));
        return result;
    }
}
